﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world {
    import flash.utils.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.models.world.vos.areas.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;

    public class WorldModel extends Actor {

		[Inject]
        public var computerModel:ComputerModel;
        private var _areas:DictStorage;
        private var _actors:DictStorage;
        private var _waitingQueue:Array;

        public function WorldModel(){
            this._areas = new DictStorage();
            this._actors = new DictStorage();
            this._waitingQueue = [];
            super();
        }
        public function reset():void{
            var _local1:IArea;
            var _local2:IActing;
            for each (_local1 in this._areas) {
                _local1.destroy();
            };
            for each (_local2 in this._actors) {
                _local2.destroy();
            };
            this._areas = new DictStorage();
            this._actors = new DictStorage();
        }
        public function addArea(_arg1:IArea):void{
            this._areas.set(_arg1.id, _arg1);
        }
        public function getArea(_arg1:String):IArea{
            return ((this._areas.get(_arg1) as IArea));
        }
        public function addRoom(_arg1:IArea):void{
            this.building.addRoom(_arg1);
        }
        public function getRoomById(_arg1:String):IArea{
            return (this.building.getRoom(_arg1));
        }
        public function getRoomIdsOfType(_arg1:String, _arg2:Boolean=false):Array{
            return (this.building.getRoomIdsOfType(_arg1, _arg2));
        }
        public function get buildRoomTypes():Array{
            return (this.building.buildRoomTypes);
        }
        public function hasAreaType(_arg1:String):Boolean{
            var _local2:IArea;
            for each (_local2 in this._areas.storage) {
                if (_local2.type == _arg1){
                    return (true);
                };
            };
            return ((this.building) ? this.building.hasAreaType(_arg1) : false);
        }
        public function getRoomOfActor(_arg1:String):IAccessible{
            return (this.building.getRoomOfActor(_arg1));
        }
        public function removeAndReturnRoom(_arg1:String):IArea{
            return (this.building.removeRoom(_arg1));
        }
        public function get actors():Dictionary{
            return (this._actors.storage);
        }
        public function get patients():Array{
            var _local2:IActing;
            var _local1:Array = [];
            for each (_local2 in this.actors) {
                if ((_local2 is ITreatable)){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function get patientsWithoutWaiting():Array{
            var _local2:IActing;
            var _local1:Array = [];
            for each (_local2 in this.actors) {
                if ((((_local2 is ITreatable)) && (!((_local2 is IWaiting))))){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function getNumberOfElders():int{
            var _local2:IActing;
            var _local1:int;
            for each (_local2 in this.actors) {
                if ((((_local2 is ITreatable)) && ((ITreatable(_local2).diseaseName == WorldConstants.DISEASE_OLD)))){
                    _local1++;
                };
            };
            return (_local1);
        }
        public function getPatientsWithoutBabies():Array{
            var _local2:IActing;
            var _local1:Array = [];
            for each (_local2 in this.actors) {
                if ((((_local2 is ITreatable)) && (!((_local2 is BabyVO))))){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function getAllRunningTreatments(_arg1:Boolean=false):Array{
            var _local5:ITreatment;
            var _local7:ITreatable;
            var _local2 = "finishedAt";
            var _local3 = 1;
            var _local4:Array = this.patients;
            var _local6:Array = [];
            for each (_local7 in _local4) {
                _local5 = _local7.currentTreatment;
                if (((((((((_local5) && (!(_local5.isFinalized)))) && (!(_local5.isFinished)))) && (!((_local5.finishedAt == 0))))) && (!((_local7.state == GameConstants.STATE_BABY))))){
                    _local6.push(_local5);
                };
            };
            if (((_arg1) && ((_local6.length > _local3)))){
                _local6.sortOn(_local2, Array.NUMERIC);
            };
            return (_local6);
        }
        public function getPatientByTreatmentId(_arg1:String):ITreatable{
            var _local4:ITreatable;
            var _local2:Array = this.patients;
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = ITreatable(_local2[_local3]);
                if (((_local4.currentTreatment) && ((_local4.currentTreatment.id == _arg1)))){
                    return ((_local2[_local3] as ITreatable));
                };
                _local3++;
            };
            return (null);
        }
        public function get avatar():IAvatar{
            return ((this.avatars[0] as IAvatar));
        }
        public function get avatars():Array{
            var _local2:IActing;
            var _local1:Array = [];
            for each (_local2 in this.actors) {
                if ((_local2 is IAvatar)){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function get doctors():Array{
            var _local2:IActing;
            var _local1:Array = [];
            for each (_local2 in this.actors) {
                if ((_local2 is ITreating)){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function get machines():Array{
            var _local2:IArea;
            var _local1:Array = [];
            for each (_local2 in this.building.rooms) {
                if ((_local2 is IRoom)){
                    _local1.push(IRoom(_local2).machine);
                };
            };
            return (_local1);
        }
        public function addActor(_arg1:IActing):void{
            this._actors.set(_arg1.id, _arg1);
            var _local2:IAccessible = (((this.getArea(_arg1.roomId) as IAccessible)) || (this.building));
            _local2.addActor(_arg1);
        }
        public function addWaitingActor(_arg1:IActing):void{
            this._actors.set(_arg1.id, _arg1);
        }
        public function getWaitingActor(_arg1:String):IActing{
            return ((this._actors.get(_arg1) as IActing));
        }
        public function getActor(_arg1:String):IActing{
            var _local2:IActing;
            var _local3:IArea;
            for each (_local3 in this._areas.storage) {
                if ((_local3 is IAccessible)){
                    _local2 = IAccessible(_local3).getActor(_arg1);
                    if (_local2){
                        break;
                    };
                };
            };
            if (!_local2){
            };
            return (_local2);
        }
        public function removeActor(_arg1:String):IActing{
            var _local2:IActing;
            var _local3:IArea;
            this.removeFromRoomQueue(_arg1);
            this._actors.remove(_arg1);
            for each (_local3 in this._areas.storage) {
                if ((_local3 is IAccessible)){
                    _local2 = IAccessible(_local3).removeActor(_arg1);
                    if (_local2){
                        break;
                    };
                };
            };
            return (_local2);
        }
        private function removeFromRoomQueue(_arg1:String):void{
            this.building.removeFromQueues(_arg1);
        }
        public function get building():BuildingVO{
            return ((this.getArea(WorldConstants.BUILDING) as BuildingVO));
        }
        public function isTreatmentRoom(_arg1:String):Boolean{
            switch (_arg1){
                case GameConstants.TYPE_TREATMENT_COSMETIC:
                case GameConstants.TYPE_TREATMENT_GENERAL:
                case GameConstants.TYPE_TREATMENT_MENTAL:
                case GameConstants.TYPE_TREATMENT_PHYSICAL:
                case GameConstants.TYPE_REHA_FUN:
                case GameConstants.TYPE_REHA_SPA:
                case GameConstants.TYPE_REHA_SPORT:
                    return (true);
            };
            return (false);
        }
        public function addToWaitingQueue(_arg1:int):WaitingVO{
            var _local2:Object = this.computerModel.matrix[(_arg1 - 1)];
            var _local3:WaitingVO = new WaitingVO(_local2, this._waitingQueue.length);
            this._waitingQueue.push(_local3);
            return (_local3);
        }
        public function removeFromWaitingQueue(_arg1:int):void{
            this._waitingQueue.splice(_arg1, 1);
        }
        public function get waitingQueue():Array{
            return (this._waitingQueue);
        }

    }
}//package net.wooga.pets.models.world 
